package cn.wolfcode.cms.service.impl;

import cn.wolfcode.cms.domain.Employee;
import cn.wolfcode.cms.domain.Stock;
import cn.wolfcode.cms.mapper.StockMapper;
import cn.wolfcode.cms.query.QueryObject;
import cn.wolfcode.cms.service.IStockService;
import cn.wolfcode.cms.util.PageResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class StockServiceImpl implements IStockService {

    @Autowired
    private StockMapper stockMapper;




    public void updateData(Stock entity,Integer newStockNumber) {

        //设置盘点更新时间
        entity.setStockTime(new Date());

        //设置盘点人
        Employee emp = (Employee) SecurityUtils.getSubject().getPrincipal();
        entity.setStockUser(emp);

        stockMapper.updateData(entity,newStockNumber);
    }

    public void delete(Long id) {

    }



    public Object query(QueryObject qo) {
        //查总数
        int total = stockMapper.queryForCount(qo);
        if (total == 0) {
            return new PageResult();
        }
        //查数据
        List<Stock> rows = stockMapper.queryForList(qo);
        return new PageResult(total, rows);
    }



}
